﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xant.FlowEngine.Core;
using Xant.FlowEngine.Interface;

namespace Xant.FlowEngine.Actor
{
    /// <summary>
    /// 岗位参与者
    /// <remarks>该部门内指定岗位的员工获得参与权</remarks>
    /// </summary>
    public class PositionActor : AbstractActor
    {
        private IOrganization organiz;
        private IPosition position;

        public PositionActor(IOrganization organiz, IPosition position)
        {
            this.organiz = organiz;
            this.position = position;
        }

        public IOrganization Organiz
        {
            get { return organiz; }
        }

        public IPosition Position
        {
            get { return position; }
        }

        public override string Text
        {
            get { return string.Format("[{0}]{1}", Organiz.FriendlyName, position.Name); }
        }

        public override string ToXml()
        {
            var xml = string.Format("<Actor Type=\"{0}\" Organization=\"{1}\" Position=\"{2}\" />", this.Type, Organiz.Id, Position.Code);
            return xml;
        }

        public override IEnumerable<IStaffMember> GetStaffs()
        {
            return Organiz.StaffMembers.Where(p => p.Position.Equals(this.Position));
        }
    }
}
